{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bukdu\n",
    "\n",
    " * https://github.com/wookay/Bukdu.jl\n",
    "\n",
    "Bukdu is a web development framework for Julia (http://julialang.org).\n",
    "\n",
    "It's influenced by Phoenix framework (http://phoenixframework.org)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Pkg.clone(\"https://github.com/wookay/Bukdu.jl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "importall Bukdu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "type WelcomeController <: ApplicationController\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "index (generic function with 1 method)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index(::WelcomeController) = \"Hello Bukdu\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Router() do\n",
    "    get(\"/\", WelcomeController, index)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Listening on 127.0.0.1:8080...\n"
     ]
    }
   ],
   "source": [
    "Bukdu.start(8080)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "open in browser: http://localhost:8080/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Method definition index(Main.WelcomeController) in module Main at In[4]:1 overwritten at In[7]:1.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "index (generic function with 1 method)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index(::WelcomeController) = render(Markdown, \"# Hello Markdown\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "open in browser: http://localhost:8080/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Method definition index(Main.WelcomeController) in module Main at In[7]:1 overwritten at In[8]:1.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "index (generic function with 1 method)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index(::WelcomeController) = render(JSON, [\"Hello\", \"JSON\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```sh\n",
    "$ curl -v http://localhost:8080/\n",
    "> GET / HTTP/1.1\n",
    "> Host: localhost:8080\n",
    "> User-Agent: curl/7.49.0\n",
    "> Accept: */*\n",
    ">\n",
    "< HTTP/1.1 200 OK\n",
    "< Connection: keep-alive\n",
    "< Content-Length: 16\n",
    "< Content-Type: application/json\n",
    "< Date: Fri, 02 Sep 2016 16:30:48\n",
    "< Content-Language: en\n",
    "< Server: Bukdu (commit 7a56c54) with Julia 0.6.0-dev.446\n",
    "[\"Hello\",\"JSON\"]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "Endpoint() do\n",
    "    plug(Plug.Logger)\n",
    "    plug(Router)\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "open in browser: http://localhost:8080/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Bukdu.stop()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.6.0-dev",
   "language": "julia",
   "name": "julia-0.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.6.0"
  },
  "widgets": {
   "state": {},
   "version": "1.1.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
